﻿using System;

namespace Outcoder.Concurrency
{
	/// <summary>
	/// This delegate is used by the default implementation of the <see cref="IMessenger"/>
	/// to allow external processing of exceptions raised during calls to publish an event.
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e">The args containing the event object, 
	/// the subscriber, and the exception raised.</param>
	/// <returns><c>true</c> if the exception has been handled 
	/// and should not be rethrown, else <c>false</c>.</returns>
	public delegate bool InvokedExceptionHandler(object sender, InvokedExceptionArgs e);

	public class InvokedExceptionArgs : EventArgs
	{
		public string MemberName { get; private set; }
		public string FilePath { get; private set; }
		public int LineNumber { get; private set; }

		/// <summary>
		/// The exception that was raised during the call to the subscriber's ReceiveMessage method.
		/// </summary>
		public Exception Exception { get; private set; }

		public InvokedExceptionArgs(string memberName, string filePath, int lineNumber, Exception exception)
		{
			MemberName = memberName;
			FilePath = filePath;
			LineNumber = lineNumber;

			Exception = ArgumentValidator.AssertNotNull(exception, "exception");
		}
	}
}
